<%@ page language="java" pageEncoding="UTF-8"
		 contentType="text/html;charset=UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	request.setAttribute("basePath", basePath);
%>
<!DOCTYPE>
<html>
<head>
	<title>明细信息</title>
	<%@ include file="/resources/js/easyui/taglibs.jsp"%>
	<%@ include file="/resources/js/easyui/_easyui.jsp"%>
	<%@ include file="/resources/js/easyui/_message.jsp"%>
	<%@ include file="/resources/js/easyui/_viewJS.jsp"%>
</head>

<body class="easyui-layout">
<form id="addform">
	<table class="tableForm" style="width: 100%;">
		<tr>
			<td>用户组名称：${usergroup.namecn}
				<input type="hidden" value="${usergroup.roleid}" name="roleid" />
			</td>
		</tr>

		<tr>
			<td id="GC_SETUP_ROLE_MODULES"></td>
		</tr>

	</table>

</form>

<script type="application/javascript">
	var role_module = ${sysRoleModules}

			function setup(){
				var checkedValues = [];
				var noChanged = true;
				$('input[name="moduleid"]:checked').each(function(){
					checkedValues.push($(this).val());
				});

				if(checkedValues.length == 0){
					$.messager.alert('提示','至少分配一个权限！','warning');
				}else if(checkedValues.length == role_module.length){
					$.each(checkedValues.sort(function(a,b){return a-b}),function(index){
						if(checkedValues[index] != role_module[index].moduleid){
							noChanged = false;
							return false;
						}
					});
				}else{
					noChanged = false;
				}

				if(noChanged){
					$.messager.alert('提示','当前权限设置尚未改变，如有更改后再保存！','warning');
				}else{
					if($("#addform").form('validate')){
						$.ajax({
							url:'${basePath}web/userGroup/setupRoleModule',
							type : 'POST',
							data : $("#addform").serialize(),
							async : false,
							traditional:true,
							error: function (response) {
								ViewHelper.func.ajaxErrorMessage(response);
							},
							success: function (ret) {
								if(ret.result) {
									$.messager.alert('提示信息！',ret.info,'info');
									parent.view.closeSetupWin(1);
									$("#addform").form('clear');
								}else{
									$.messager.alert('提示','保存失败!','error');
								}
							}
						});
					}
				}
			};;;;;

	$(function() {

		/* $.each(role_module,function(i,item){
		 $("input[name='moduleid'][value='"+item+"']").attr("checked",'true');
		 }); */

		$.ajax({
			type:'GET',
			url:'${basePath}web/userGroup/module.json',
			dataType:'json',
			success:function(data){
				$.each(data,function(key,values){
					var modulelistname = '';

					if(key == 1){
						modulelistname = 'web视图权限';
					}else if(key == 2){
						modulelistname = '微信视图权限';
					}else if(key == 3){
						modulelistname = 'app视图权限';
					}else if(key == 4){
						modulelistname = '操作视图权限';
					}

					var modulelist = '<div style="whith:100%;">'+modulelistname+'<ul style="height:70px;" id="GC_ROLE_MODULES_UL'+key+'"></ul></div>';

					$("#GC_SETUP_ROLE_MODULES").append(modulelist);

					init(values,key);
				});

				$.each(role_module,function(i,item){
					$("input[name='moduleid'][value='"+item+"']").attr("checked",'true');
				});
			},
			error:function(){
				alert("获取数据失败!");
			}
		});
	});

	function init(menus,key){
		$.each(menus,function(i,item){
			$('#GC_ROLE_MODULES_UL'+key).append('<li style="list-style-type:none;float:left;margin-left:4px; "><input type="checkbox" name="moduleid" value="'+item.id+'" />'+item.text+'</li>');
			var chidrenItem = item.children;
			if(typeof(chidrenItem) != "undefined" && chidrenItem != null) {
				init(chidrenItem,key);
			}
		});
	}
</script>
</body>
</html>
